// pages/mine/mine.js
import urls from '../../utils/urls.js'
import loginFn from '../../utils/login.js'
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		learned: [],
		schoolId: 0,
		courseId: 0,
		teacherId: 0
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {
		console.log('options:',options);
		var that = this;
		if (options.courseId) {
			var loginInfo = loginFn()
			loginInfo.courseId = options.courseId
			wx.request({
				url: urls.courselearned,
				data: loginInfo,
				method: 'POST',
				success: function(res) {
					console.log(res)
					if (res.data.code == '0') {
						that.setData({
							courseId: options.courseId,
							learned: res.data.data
						})
					}
				}
			})
		};

		if (options.schoolId) {
			var loginInfo = loginFn()
			loginInfo.schoolId = options.schoolId
			wx.request({
				url: urls.schoollearn,
				data: loginInfo,
				method: 'POST',
				success: function(res) {
					console.log(res)
					if (res.data.code == '0') {
						that.setData({
							schoolId: options.schoolId,
							learned: res.data.data
						})
					}
				}
			})
		};

		if (options.teacherId) {
			var loginInfo = loginFn()
			loginInfo.teacherId = options.teacherId
			wx.request({
				url: urls.schoollearn,
				data: loginInfo,
				method: 'POST',
				success: function(res) {
					console.log(res)
					if (res.data.code == '0') {
						that.setData({
							teacherId: options.teacherId,
							learned: res.data.data
						})
					}
				}
			})
		}



	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function() {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function() {

	},
	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function() {

	}








})
